let app = getApp();

Component({
  externalClasses: ['customize-class'],
  properties: {
    flg: {
      type: Boolean,
      value: false,
    },
  },
  data: {
    copyright1: false, // 版权信息
    copyright2: false,
  },
  methods: {
    getCopyright() {
      let _this = this;
      app.util.request({
        url: 'auth/session/copyright',
        cachetime: 0,
        success: function (res) {
          if (res.data.data && !!res.data.data.demonstration) _this.triggerEvent('demonstration', { demonstration: res.data.data.demonstration });
          if (res.data.data && res.data.data.wxapp_copyright.copyright_wxapp) {
            let agent_copyright = res.data.data.founder_copyright;
            let user_copyright = res.data.data.wxapp_copyright.copyright_wxapp_content;
            let copyright_type = Number(res.data.data.wxapp_copyright.copyright_wxapp);
            let agentCopyrightUrl = agent_copyright && (agent_copyright.founder_copyrighturl || '');
            _this.agentCopyrightUrl = agentCopyrightUrl;
            if (copyright_type === 0) {
              _this.setData({
                copyright2: agent_copyright,
              });
            } else if (copyright_type === 1) {
              _this.setData({
                copyright1: user_copyright,
              });
            } else if (copyright_type === 2) {
              _this.setData({
                copyright1: user_copyright,
                copyright2: agent_copyright,
              });
            }
          } else {
            console.log(`copyright数据不存在`);
          }
          _this.triggerEvent('copyrightLoaded', res);
        },
        fail: function (err) {
          console.log(`copyright获取失败 ${err}`);
        },
      });
    },

    navigate() {
      this.triggerEvent('navigateToWeb', { agentCopyrightUrl: this.agentCopyrightUrl });
    },
  },
  ready() {
    this.getCopyright();
  },
});
